package com.hengxinguotong.hxgtwygsp.ui.imgView;

import android.content.Context;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;

import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseDialogActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 填充图片的Activity
 * Created by CS-Yong
 * 2019/8/30  13:22
 */
public class ImgViewActivity extends BaseDialogActivity {
    @BindView(R.id.tv_img_title)
    TextView mTvImgTitle;
    @BindView(R.id.member_close)
    ImageView mMemberClose;
    @BindView(R.id.iv_fill_img)
    ImageView mIvFillImg;

    private String mTitle;
    private int mImgName;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_img_view;
    }

    @Override
    public void init() {
        mTitle = getIntent().getStringExtra("title");
        mImgName = getIntent().getIntExtra("imgName",R.mipmap.ic_empty_content);
        mTvImgTitle.setText(mTitle);

        mIvFillImg.setImageResource(mImgName);


//        Glide.with(this)
//                .load(mImgName)
//                .apply(glideOptions)
//                .listener(new RequestListener<Drawable>() {
//                    @Override
//                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
//                        return false;
//                    }
//                    @Override
//                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
//                        //加载图片，并设置图片铺面页面，可滑动
//                        if (mIvFillImg == null) {
//                            return false;
//                        }
//                        if (mIvFillImg.getScaleType() != ImageView.ScaleType.FIT_XY) {
//                            mIvFillImg.setScaleType(ImageView.ScaleType.FIT_XY);
//                        }
//                        ViewGroup.LayoutParams params = mIvFillImg.getLayoutParams();
//                        int vw = mIvFillImg.getWidth() - mIvFillImg.getPaddingLeft() - mIvFillImg.getPaddingRight();
//                        float scale = (float) vw / (float) resource.getIntrinsicWidth();
//                        int vh = Math.round(resource.getIntrinsicHeight() * scale);
//                        params.width = vw;
//                        params.height = vh + mIvFillImg.getPaddingTop() + mIvFillImg.getPaddingBottom();
//
//                        Log.e("img","图片尺寸："+resource.getIntrinsicWidth()+"xxxx"+resource.getIntrinsicHeight()+
//                                "\n容器尺寸："+params.width+"xxxxx"+params.height);
//
//                        mIvFillImg.setLayoutParams(params);
//                        return false;
//                    }
//                })
//                .into(mIvFillImg);

    }

    @OnClick(R.id.member_close)
    public void onViewClicked() {
        finish();
    }

    public static void startAction(Context context,String title,int imgName){
        Intent intent = new Intent(context, ImgViewActivity.class);
        intent.putExtra("title",title);
        intent.putExtra("imgName",imgName);
        context.startActivity(intent);
    }
}
